package com.retail.help.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;

import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.security.LoginUserUtil;
import com.retail.global.annon.TraceLog;
import com.retail.help.entity.request.RetailHelpRequest;
import com.retail.help.entity.vo.RetailHelpVo;
import com.retail.help.service.RetailHelpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 帮助文档 API
* @author Administrator
*/
@Api(tags = "帮助文档 API")
@RestController
@RequestMapping("/retailHelp")
public class RetailHelpController extends AbstractCommonController<RetailHelpService, RetailHelpRequest, RetailHelpVo>{

    private final RetailHelpService retailHelpService;

    public RetailHelpController(RetailHelpService retailHelpService) {
        this.retailHelpService = retailHelpService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(retailHelpService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存帮助文档")
    public Result<Integer> save(@RequestBody RetailHelpRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(retailHelpService, request);
    }


    /**
     * 插入协议
     * @param request
     * @return
     */
    @PostMapping("insertXieyiRetailHelp")
    @ApiOperation("保存帮助文档")
    public Result<Integer> insertXieyiRetailHelp(@RequestBody RetailHelpRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return retailHelpService.insertXieyiRetailHelp(request);
    }

    /**
     * 得到协议
     * @param xieyiType
     * @return
     */
    @GetMapping("getXieyiRetailHelp/{xieyiType}")
    @ApiOperation("得到协议")
    public Result<RetailHelpVo> getXieyiRetailHelp(@PathVariable("xieyiType") String xieyiType) {
        return retailHelpService.getXieyiRetailHelp(xieyiType);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新帮助文档")
    public Result<Integer> update(@RequestBody RetailHelpRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(retailHelpService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("帮助文档-查询")
    public Result<List<RetailHelpVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(retailHelpService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("帮助文档-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(retailHelpService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("帮助文档-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<RetailHelpRequest> req) {
        return super.page(retailHelpService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除帮助文档")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(retailHelpService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除帮助文档")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(retailHelpService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
